//
//  NSURL+MarsQuery.m
//  WKWebDemo
//
//  Created by yangpenghua on 2018/3/27.
//  Copyright © 2018年 linzi. All rights reserved.
//

#import "NSURL+MarsQuery.h"

@implementation NSURL (MarsQuery)

/** 获取query 参数字典 */
- (NSDictionary *)mars_queryParams{
    NSURLComponents *urlComp = [[NSURLComponents alloc] initWithURL:self resolvingAgainstBaseURL:NO];
    NSArray *queryArray = urlComp.queryItems;
    NSMutableDictionary *paramDict = [NSMutableDictionary dictionary];
    for (int i = 0; i < queryArray.count; i ++) {
        NSURLQueryItem *queryItem = queryArray[i];
        if (queryItem.name && queryItem.value) {
            [paramDict setValue:queryItem.value forKey:queryItem.name];
        }
    }
    return paramDict;
}

@end
